package com.hpf.lease.web.admin.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hpf.lease.common.config.CommonException;
import com.hpf.lease.common.result.ResultCodeEnum;
import com.hpf.lease.model.bean.AttrValue;
import com.hpf.lease.web.admin.mapper.AttrValueMapper;
import com.hpf.lease.web.admin.service.AttrValueService;
import org.springframework.stereotype.Service;

/**
* @author GOD
* @description 针对表【attr_value(房间基本属性值表)】的数据库操作Service实现
* @createDate 2024-08-29 15:00:50
*/
@Service
public class AttrValueServiceImpl extends ServiceImpl<AttrValueMapper, AttrValue>
    implements AttrValueService {

    @Override
    public Boolean saveOrUpdateInfo(AttrValue attrValue) {
        Long id = attrValue.getId() == null ? -1L :  attrValue.getId();
        AttrValue one = this.getOne(Wrappers.lambdaQuery(AttrValue.class)
                .eq(AttrValue::getId, attrValue.getId())
                .eq(AttrValue::getName, attrValue.getName())
                .last("limit 1")
        );
        if (one != null && !attrValue.getId().equals(id)){
            throw new CommonException(ResultCodeEnum.ADMIN_CAPTCHA_CODE_NOT_FOUND);
        }
        return this.saveOrUpdate(attrValue);
    }
}




